package com.gitee.cashzhang27.test.boot.other.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/08/05 10:43
 */
@RestController
@RequestMapping("/json/redis")
@AllArgsConstructor
@Api(value = "JsonRedisController", description = "redis中村json")
public class JsonRedisController {

  private JedisPool jedisPool;

  @GetMapping("test1")
  public void test1() {
    try (Jedis jedis = jedisPool.getResource()) {
      JSONObject jsonObject = JSONUtil.createObj();
      jsonObject.put("accessToken", "123456789");
      jsonObject.put("refreshToken", "258654");
      String jsonStr = JSONUtil.toJsonStr(jsonObject);
      System.out.println(jsonStr);
      jedis.lpush("test", jsonStr);

      List<String> test = jedis.lrange("test", 0, -1);
      for (String value : test) {
        JSONObject parseObj = JSONUtil.parseObj(value);
        Object accessToken = parseObj.get("accessToken");
        System.out.println(accessToken);
      }
    }

  }


}
